package netty.io.demo.Buffer;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

public class Demo02 {
  public static void main(String[] args) {
    // 这里 申请 堆内存
    ByteBuffer buffer = ByteBuffer.allocate(1024);
    
    String t1 = "hello world01";
    buffer.put(t1.getBytes());
    System.out.println(buffer.position());
    // 从这里进行标记
    buffer.mark();
    
    buffer.flip();
    byte[] bytes = new byte[26];
    buffer.get(bytes);
    System.out.println(new String(bytes, StandardCharsets.UTF_8));
    
    // 回退 到mark 标记
    buffer.reset();
    byte[] bytes1 = new byte[26];
    buffer.get(bytes1);
    System.out.println(new String(bytes1, StandardCharsets.UTF_8));
  }
}
